﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using FluentValidation;
using CashFlow.ShopManage.Models.Order;
using CashFlow.ShopManage.Common;

namespace CashFlow.ShopManage.Validator.Order
{
    public class CreateOrderModelValidator
        : AbstractValidator<CreateOrderModel>
    {
        public CreateOrderModelValidator()
        {
            CascadeMode = CascadeMode.Stop;
            RuleFor(x => x.BuyerUserId).Must(x => ValidatorTool.IsUserIdValiadState(x))
                .WithMessage("非法BuyerUserId")
                .Must(x => ValidatorTool.IsUserBelongsMyShop(x))
                .WithMessage("非法BuyerUserId");
            RuleFor(x => x.SellerUserId).Must(x => ValidatorTool.IsUserIdValiadState(x))
                .WithMessage("非法SellerUserId")
                .Must(x => ValidatorTool.IsUserBelongsMyShop(x))
                .WithMessage("非法SellerUserId");
            RuleFor(x => x.Amount).Must(x => MyCommonTool.ValidateOrderAmount(x))
                .WithMessage("订单金额错误！");
        }
    }
}